﻿
using System.IO;
using Super_Management_Mayhem.Screens.Playing.Players;
using Transformable_Engine_v2.Engine.Graphics;
using Transformable_Engine_v2.Engine.Network;

namespace Super_Management_Mayhem.Screens.Menu
{
    public class ProfileData
    {
        public string Name { get; set; }
        public int Color { get; set; }
        public int Icon { get; set; }
        public int GamesPlayed { get; set; }
        public int Level { get; set; }

        private Team _team;
        public Team Team
        {
            get
            {
                if(_team == null)
                    _team = new Team(Color, Name);

                return _team;
            }
            set { _team = value; }
        }

        public int Id { get; set; }

        public Color GetColor()
        {
            return CreateAvatarColor.AvatarColorMenu.AvailableColors[Color];
        }

        public ProfileData()
        {
            Name = "";
            Icon = 0;
            Color = 0;
            GamesPlayed = 0;
            Level = 1;
            Team = null;
            Id = -1;
        }

        public void Save()
        {
            Team = null;
            Id = -1;

            if(!Directory.Exists("Content/Config/Profiles"))
                Directory.CreateDirectory("Content/Config/Profiles");
            File.WriteAllBytes("Content/Config/Profiles/" + Name + ".profile", Serialization.Serialize(this));
        }

        public static ProfileData FromFile(string filePath)
        {
            byte[] data = File.ReadAllBytes(filePath);

            return Serialization.Deserialize<ProfileData>(data);
        }
    }
}